#include "utils.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

#include <lua.h>
#include <lauxlib.h>

static int lgetmillisecond (lua_State *L) {

    struct timeval tv;
    gettimeofday(&tv,NULL);

    lua_Integer t = tv.tv_sec*1000 + tv.tv_usec/1000;

    lua_pushinteger(L,t);

    return 1;
}

static struct luaL_Reg utilslib[] = {
        {"getmillisecond", lgetmillisecond},
        {NULL, NULL}
};

int luaopen_utils_core (lua_State *L)
{
    lua_newtable(L);
    luaL_setfuncs(L, utilslib, 0);
    return 1;
}